# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@com_google_googleapis_imports//:imports.bzl", "cc_proto_library")

# Placeholder: load py_binary
load("//p4_symbolic/bmv2:test.bzl", "bmv2_protobuf_parsing_test")

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

cc_proto_library(
    name = "bmv2_cc_proto",
    deps = [":bmv2_proto"],
)

proto_library(
    name = "bmv2_proto",
    srcs = [
        "bmv2.proto",
    ],
    deps = [
        "@com_google_protobuf//:struct_proto",
    ],
)

cc_library(
    name = "bmv2",
    srcs = [
        "bmv2.cc",
    ],
    hdrs = [
        "bmv2.h",
    ],
    deps = [
        ":bmv2_cc_proto",
        "//gutil/gutil:io",
        "//gutil/gutil:status",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_binary(
    name = "test",
    srcs = ["test.cc"],
    deps = [
        ":bmv2",
        "//gutil/gutil:io",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/flags:usage",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_protobuf//:protobuf",
    ],
)

py_binary(
    name = "test_sdiff",
    srcs = ["test_sdiff.py"],
    python_version = "PY3",
)

# Test rules: one per program in //p4-samples
bmv2_protobuf_parsing_test(
    name = "port_table",
    golden_file = "expected/table.pb.txt",
    p4_program = "//p4_symbolic/testdata:port-table/table.p4",
)

bmv2_protobuf_parsing_test(
    name = "ipv4_routing",
    golden_file = "expected/basic.pb.txt",
    p4_program = "//p4_symbolic/testdata:ipv4-routing/basic.p4",
)

bmv2_protobuf_parsing_test(
    name = "port_hardcoded",
    golden_file = "expected/hardcoded.pb.txt",
    p4_program = "//p4_symbolic/testdata:hardcoded/hardcoded.p4",
)

bmv2_protobuf_parsing_test(
    name = "reflector",
    golden_file = "expected/reflector.pb.txt",
    p4_program = "//p4_symbolic/testdata:reflector/reflector.p4",
)

bmv2_protobuf_parsing_test(
    name = "table_hit_1",
    golden_file = "expected/table_hit_1.pb.txt",
    p4_program = "//p4_symbolic/testdata:conditional/table_hit_1.p4",
)

bmv2_protobuf_parsing_test(
    name = "table_hit_2",
    golden_file = "expected/table_hit_2.pb.txt",
    p4_program = "//p4_symbolic/testdata:conditional/table_hit_2.p4",
)

bmv2_protobuf_parsing_test(
    name = "set_invalid",
    golden_file = "expected/set_invalid.pb.txt",
    p4_program = "//p4_symbolic/testdata:set-invalid/set_invalid.p4",
)
